package com.atguigu.eduService.controller;


import com.atguigu.commonUtils.Result;
import com.atguigu.commonUtils.ResultUtil;
import com.atguigu.eduService.entity.EduTeacher;
import com.atguigu.eduService.service.EduTeacherService;
import com.atguigu.eduService.vo.TeacherQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 讲师 前端控制器
 * </p>
 *
 * @author Chen Wen bo
 * @since 2021-07-09
 */
@Api(tags = "讲师管理")
@RestController
@RequestMapping("/eduService/teacher")
@CrossOrigin
public class EduTeacherController {

    @Resource
    private EduTeacherService eduTeacherService;

    //查询所有讲师
    @GetMapping("/findAll")
    @ApiOperation("查询所有讲师")
    public Result<List<EduTeacher>> findAllTeacher(){
        List<EduTeacher> teachers = eduTeacherService.findAllTeacher();
        return ResultUtil.success(teachers);
    }

    //逻辑删除讲师
    @DeleteMapping("/{id}")
    @ApiOperation("逻辑删除讲师")
    public Result<Boolean> deleteTeacher(@ApiParam(name = "id", value = "讲师id", required = true) @PathVariable String id) {
        eduTeacherService.deleteTeacherById(id);
        return ResultUtil.success();
    }

    //分页查询讲师
    @ApiOperation("分页查询讲师")
    @GetMapping("/pageTeacher/{current}/{size}")
    public Result<IPage<EduTeacher>> pageListTeacher(@PathVariable @ApiParam(name = "current", value = "当前页", required = true) Long current,
                                                     @PathVariable @ApiParam(name = "size", value = "每页记录数", required = true) Long size) {
        return ResultUtil.success(eduTeacherService.selectTeacherPage(current,size));
    }

    //根据分页条件查询
    @ApiOperation("根据分页条件查询讲师")
    @PostMapping("/pageTeacherCondition/{current}/{size}")
    public Result<IPage<EduTeacher>> pageTeacherCondition(@PathVariable @ApiParam(name = "current", value = "当前页", required = true) Long current,
                                                       @PathVariable @ApiParam(name = "size", value = "每页记录数", required = true) Long size,
                                                       @RequestBody(required = false) TeacherQueryVo teacherQueryVo){ //@RequestBody：@RequestBody需要使用POST提交方式
        return ResultUtil.success(eduTeacherService.selectTeacherPageCondition(current, size, teacherQueryVo));
    }

    @ApiOperation("添加讲师")
    @PostMapping("/addTeacher")
    public Result<EduTeacher> addTeacher(@RequestBody EduTeacher eduTeacher){
        eduTeacherService.addTeacher(eduTeacher);
        return ResultUtil.success();
    }

    @ApiOperation("根据id获取讲师")
    @GetMapping("/getTeacher/{id}")
    public Result<EduTeacher> getTeacher(@PathVariable String id){
        EduTeacher eduTeacher = eduTeacherService.getTeacherById(id);
        return ResultUtil.success(eduTeacher);
    }

    @ApiOperation("修改讲师")
    @PutMapping("/updateTeacher")
    public Result<EduTeacher> updateTeacher(@RequestBody EduTeacher eduTeacher){
        eduTeacherService.updateTeacher(eduTeacher);
        return ResultUtil.success();
    }




}

